home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 10.1 KB | 246 lines | [TEXT/ttxt] |
- --<<<-
- --*******************************************************************************
- --* Demo for: MenuButton
- --* Required files: reqFiles/button.sx
- --* bmpmenu.sx
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*-----------------------------------------------------------------------------*
- --* Description: This script demonstrates how to create a hierarchical
- --* menu using bitmaps.
- --* When you run "bmpmenu.sxt", you should see a window
- --* with a settings menu with the following menu structure:
- --*
- --* Settings - Reset
- --* - Color - Fill - Red
- --* - Green
- --* - Blue
- --* - Stroke - Red
- --* - Green
- --* - Blue
- --*
- --*******************************************************************************
-
- module BitmapMenuModule
- uses ScriptX
- end
-
- in module BitmapMenuModule
-
- --*=============================================================================*
- --* Set up DirReps
- --*=============================================================================*
- global demoDir := theScriptDir
- global mediaDir := spawn theScriptDir "media"
- global reqFilesDir := spawn theScriptDir "reqfiles"
-
- --*=============================================================================*
- --* Load required files
- --*=============================================================================*
- -- Load Button
- fileIn reqFilesDir name:"button.sx"
-
- -- Load MenuButton
- fileIn demoDir name:"bmpmenu.sx"
-
- --*=============================================================================*
- --* Define Demo
- --*=============================================================================*
- class Demo (Window)
- end
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: Demo
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class Demo} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
- colormap:theColormap container:self.title
- return theBMP
- )
-
- --*=============================================================================*
- --* Method name: makeMenu
- --* Class: Demo
- --* Usage: makeMenu self
- --*-----------------------------------------------------------------------------*
- --* Description: Makes the menu and its submenus.
- --*=============================================================================*
- method makeMenu self {class Demo} ->
- (
- --*=========================================================================*
- --* Import all required bitmaps
- --*=========================================================================*
- local mediaDir := spawn theScriptDir "media"
- local setRelBitmap := (importBitmap self mediaDir "setrel.bmp")
- local resetRelBitmap := (importBitmap self mediaDir "resetrel.bmp")
- local colorRelBitmap := (importBitmap self mediaDir "colorrel.bmp")
- local fillRelBitmap := (importBitmap self mediaDir "fillrel.bmp")
- local strokRelBitmap := (importBitmap self mediaDir "strokrel.bmp")
- local redRelBitmap := (importBitmap self mediaDir "redrel.bmp")
- local greenRelBitmap := (importBitmap self mediaDir "greenrel.bmp")
- local blueRelBitmap := (importBitmap self mediaDir "bluerel.bmp")
-
-
- local setPrsBitmap := (importBitmap self mediaDir "setprs.bmp")
- local resetPrsBitmap := (importBitmap self mediaDir "resetprs.bmp")
- local colorPrsBitmap := (importBitmap self mediaDir "colorprs.bmp")
- local fillPrsBitmap := (importBitmap self mediaDir "fillprs.bmp")
- local strokPrsBitmap := (importBitmap self mediaDir "strokprs.bmp")
- local redPrsBitmap := (importBitmap self mediaDir "redprs.bmp")
- local greenPrsBitmap := (importBitmap self mediaDir "greenprs.bmp")
- local bluePrsBitmap := (importBitmap self mediaDir "blueprs.bmp")
-
-
- --*=========================================================================*
- --* Create the settings menu
- --* Note: the 'supermenu' keyword is 'undefined'
- --*=========================================================================*
- local settingsMenu := new MenuButton supermenu:undefined \
- releasedBitmap:setRelBitmap \
- pressedBitmap:setPrsBitmap
-
- --*=========================================================================*
- --* Create the reset item under the settings menu
- --*=========================================================================*
- addmenuitem settingsMenu resetRelBitmap resetPrsBitmap self (authordata me -> \
- authordata.fill := authordata.stroke := blackBrush)
-
-
- --*=========================================================================*
- --* Create the color sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. settingsMenu
- --*=========================================================================*
- local colorMenu := new MenuButton supermenu:settingsMenu \
- placement:@menuRight \
- releasedBitmap:colorRelBitmap \
- pressedBitmap:colorPrsBitmap
-
- --*=========================================================================*
- --* Create the fill sub-sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. colorMenu
- --*=========================================================================*
- local fillMenu := new MenuButton supermenu:colorMenu \
- placement:@menuRight \
- releasedBitmap:fillRelBitmap \
- pressedBitmap:fillPrsBitmap
-
- --*=========================================================================*
- --* Create the red, green and blue items under the fill menu
- --*=========================================================================*
- addmenuitem fillMenu redRelBitmap redPrsBitmap self (authordata me -> \
- authordata.fill := (new Brush color:redColor))
- addmenuitem fillMenu greenRelBitmap greenPrsBitmap self (authordata me -> \
- authordata.fill := (new Brush color:greenColor))
- addmenuitem fillMenu blueRelBitmap bluePrsBitmap self (authordata me -> \
- authordata.fill := (new Brush color:blueColor))
-
-
- --*=========================================================================*
- --* Create the stroke sub-sub-menu
- --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
- --* i.e. colorMenu
- --*=========================================================================*
- local strokeMenu := new MenuButton supermenu:colorMenu \
- placement:@menuRight \
- releasedBitmap:strokRelBitmap \
- pressedBitmap:strokPrsBitmap
-
- --*=========================================================================*
- --* Create the red, green and blue items under the fill menu
- --*=========================================================================*
- addmenuitem strokeMenu redRelBitmap redPrsBitmap self (authordata me -> \
- authordata.stroke := (new Brush color:redColor))
- addmenuitem strokeMenu greenRelBitmap greenPrsBitmap self (authordata me -> \
- authordata.stroke := (new Brush color:greenColor))
- addmenuitem strokeMenu blueRelBitmap bluePrsBitmap self (authordata me -> \
- authordata.stroke := (new Brush color:blueColor))
-
- return settingsMenu
- )
-
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Demo
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates a 200x200 window.
- --*=============================================================================*
- method init self {class Demo} #rest args ->
- (
- -- Create a 200x200 window
- apply nextMethod self boundary:(new Rect x2:200 y2:200) \
- centered:true \
- fill:blackBrush \
- stroke:blackBrush \
- name:"Select from Menu" args
- return self
- )
-
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Demo
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Makes the menu and appends it to the demo window.
- --*=============================================================================*
- method afterInit self {class Demo} #rest args ->
- (
- --*=========================================================================*
- --* Create an actuator controller to control all the buttons in the demo
- --* window.
- --*=========================================================================*
- new ActuatorController space:self wholespace:true
-
- --*=========================================================================*
- --* Add menu to the demo window and display it
- --*=========================================================================*
- prepend self (makeMenu self)
- show self
-
- return self
- )
-
-
- --*=============================================================================*
- --* Create a title container
- --*=============================================================================*
- object tc (TitleContainer)
- dir : theScriptDir
- path : "bmpmenu.sxt"
- name : "Hierarchical Bitmap Menu"
- end
-
- --*=============================================================================*
- --* Create demo
- --*=============================================================================*
- object win (Demo)
- title:tc
- end
-
- --*=============================================================================*
- --* Undefine global DirReps
- --*=============================================================================*
- demoDir := undefined
- mediaDir := undefined
- reqFilesDir := undefined
-
- --*=============================================================================*
- --* Store module in the title container
- --*=============================================================================*
- append tc (getModule @BitmapMenuModule)
- tc.startUpAction := (tc -> load tc[1]
- show win)
- close tc
- -->>>